<% layout('/layouts/default.html', {title: '指标汇总', libs: ['layout','dataGrid','inputmask','ueditor']}){ %>
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header" style="padding-bottom: 4px;">
                <div class="box-title">
                    <i class="fa "> <a href="#" class="btn btn-primary" onclick="saveVersion()" id="save" style=""
                                       title="${text(" 保存版本")}">保存版本</a>
                    </i>
                    <i class="fa "><a href="#" onclick="publishVersion()" class="btn btn-primary" id="push" style=""
                                      title="${text(" 发布")}"> 发布</a></i>
                </div>
            </div>
            <#form:hidden path="versionNumber" id="mainVersion"/>
            <#form:hidden path="remarks2" id="version_name"/>
            <#form:hidden path="remarks3" id="batch_flag"/>
            <div class="box-body">
                <div class="input-group">
                    <#form:input path="taskDesc" maxlength="1000" class="form-control " placeholder="请输入单位名称"
                    autocomplete="off"/>
                    <span class="input-group-addon" onclick="searchTaskDesc()" style="cursor: pointer">查询</span>
                    <span class="input-group-addon" onclick="reset()" style="cursor: pointer">重置</span>
                </div>
            </div>
        </div>
        <div class="demo-class">
            <table id="leftDataGrid"></table>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <iframe id="mainFrame" name="mainFrame" class="ui-layout-content p0"></iframe>
</div>
<% } %>
<style>
    #leftDataGrid tr {
        cursor: pointer;
    }

    .SelectBG td {
        background: #eaeaea !important;
        background-color: #eaeaea !important;
        color: blue;
    }


</style>
<script>
    // 初始化布局
    $('body').layout({
        west__initClosed: $(window).width() <= 767, // 是否默认关闭
        west__size: 200,
        onresize_end: function () {
            $('#leftDataGrid').dataGrid('resize');
        }
    });
    var win = $("#mainFrame")[0].contentWindow;
    let dcSupExamSumQuota =${toJson(dcSupExamSumQuota)};

    function isUndefined(dataInfo){
       if (dataInfo == undefined){
           return '';
       }
       return dataInfo;
    }



    function reload(exameOrg, exameOrgName) {
        $('#mainFrame').attr('src', '${ctx}/quota/dcSupExamSumQuotaInfo/rightInfo?examId=' + dcSupExamSumQuota.examId + '&exameOrg=' + exameOrg + '&exameOrgName=' + exameOrgName + '&examYear=' + dcSupExamSumQuota.remarks2 + '&versionNumber=' + isUndefined(dcSupExamSumQuota.versionNumber) + '&remarks3=' + $("#batch_flag").val() + "&versionName=" + dcSupExamSumQuota.versionName);
    }

    // 展示左侧被考核单位数据
    $('#leftDataGrid').dataGrid({
        data: ${toJson(assessmentUnit)},
        datatype: "local", // 设置本地数据
        sortableColumn: false, // 禁止排序
        autoGridHeight: function () {
            var height = $(window).height() - 170;
            return height;
        }, // 设置自动高度
        columnModel: [
            {header: '${text("任务id")}', name: 'examId', hidden: true, width: 150, align: "left"},
            {header: '${text("考核单位code")}', name: 'exameOrg', hidden: true, width: 150, align: "left"},
            {
                header: '${text("被考核单位")}', name: 'exameOrgName', width: 150, align: "left", classes: ""
            },
        ],
        emptyDataHint: true,
        altRows: false,
        // 选择行后调用（id:行id，isSelect：是否是选中，event：事件）
        onSelectRow: function (id, isSelect, event) {
            let selectRow = $('#leftDataGrid').dataGrid('getRowData', id);
            $('#mainFrame').attr('src', '${ctx}/quota/dcSupExamSumQuotaInfo/rightInfo?examId=' + dcSupExamSumQuota.examId + '&exameOrg=' + selectRow.exameOrg + '&exameOrgName=' + selectRow.exameOrgName + '&examYear=' + dcSupExamSumQuota.remarks2 + '&versionNumber=' + isUndefined(dcSupExamSumQuota.versionNumber) + '&remarks3=' + $("#batch_flag").val() + "&versionName=" + dcSupExamSumQuota.versionName+"&quotaTypes="+isUndefined(dcSupExamSumQuota.types));
        },
        // 加载成功默认设置选择第一个
        ajaxSuccess: function (data) {
            if (data.total > 0) {
                let row = data.rows[0];
                reloadIndex();
                $('#mainFrame').attr('src', '${ctx}/quota/dcSupExamSumQuotaInfo/rightInfo?examId='+dcSupExamSumQuota.examId+'&exameOrg='+row.exameOrg+'&exameOrgName='+row.exameOrgName+'&examYear='+dcSupExamSumQuota.remarks2+'&versionNumber='+isUndefined(dcSupExamSumQuota.versionNumber)+'&remarks3='+$("#batch_flag").val()+"&versionName="+dcSupExamSumQuota.versionName+"&quotaTypes="+ isUndefined(dcSupExamSumQuota.types));
            }
        }
    });

    function refreshStyle() {
        $('#leftDataGrid tr').siblings().removeClass('ui-state-highlight SelectBG')
        $('#leftDataGrid tr').eq(1).addClass('ui-state-highlight');
        $('#leftDataGrid tr').eq(1).addClass('SelectBG');
    }

    function reloadIndex() {
        $('#leftDataGrid tr').eq(1).addClass('SelectBG');
        $('#leftDataGrid tr').click(function () {
            $(this).siblings().removeClass('SelectBG');
            $(this).addClass('SelectBG');
        })
    }

    $('.demo-class').attr('class', 'position: relative; visibility: visible;');

    // 任务信息的onchange事件
    function searchTaskDesc() {
        // 获取用户输入查询项
        let tempTaskDesc = $("#taskDesc").val();
        if (tempTaskDesc != '' && tempTaskDesc != undefined) {
            // 记录目标值
            let targetList = [];
            // 遍历表格数据，获取目标值
            let tempList = ${toJson(assessmentUnit)}
            for (let i = 0; i < tempList.length; i++) {
                if (tempList[i].exameOrgName.indexOf(tempTaskDesc) != -1) {
                    targetList.push(tempList[i]);
                }
            }
            // 刷新表格数据
            $('#leftDataGrid').dataGrid('setParam', {
                data: targetList
            }, true).dataGrid('reloadGrid');
        } else {
            $('#leftDataGrid').dataGrid('setParam', {
                data:${toJson(assessmentUnit)}
            }, true).dataGrid('reloadGrid');
        }
    }

    // 重置表格数据
    function reset() {
        // 重置查询项
        $("#taskDesc").val('');
        // 重置表格数据
        $('#leftDataGrid').dataGrid('setParam', {
            data:${toJson(assessmentUnit)}
        }, true).dataGrid('reloadGrid');
    }

    function saveVersion() {
        layer.open({
            type: 2,
            title: ['确认版本'],
            area: ['800px', '600px'],
            // groupId 随便传  isGroupOptions 非常用组功能使用传 0  type  1 为区县 2 为市直
            content: "${ctx}/quota/dcSupExamSumQuotaInfo/saveVersionPage?versionNumber=" + $("#mainVersion").val() + "&examId=${dcSupExamSumQuota.examId}&remarks2=" + $("#version_name").val(),
            success: function (layero, index) {
            }, end: function () {
                window.parent.baseRefresh();
            }
        })

    }

    function publishVersion() {
        if (isUndefined(dcSupExamSumQuota.versionNumber) == '') {
            js.showMessage("初始版本不允许发布，请先保存版本后操作!!!");
            return;
        }
        js.confirm('确认发布吗？', "${ctx}/quota/dcSupExamSumQuotaInfo/publish?versionNumber=" + isUndefined(dcSupExamSumQuota.versionNumber) + "&examId=${dcSupExamSumQuota.examId}",
            function (data) {
                js.showMessage(JSON.parse(JSON.stringify(data)).message)
                var result = JSON.parse(JSON.stringify(data)).result;
                if (result == Global.TRUE) {
                    $('#leftDataGrid').dataGrid('refresh', 1, 20);
                    $('#leftDataGrid tr').eq(1).addClass('SelectBG')
                    window.parent.baseRefresh();
                }

            }, 'json', true, '正在发布...');
    }
</script>
